//
//  ViewController.m
//  AFNetworking
//
//  Created by zhiyou on 16-4-13.
//  Copyright (c) 2016年 wangyang. All rights reserved.
//

#import "ViewController.h"
#import "MyRequest.h"
#define BASE_URL @"http://www.shihuo.cn/app2/getNewsDetail?id=192257&token=058150cc5aaef94e1b7383c74e424841"

@interface ViewController ()

@property (nonatomic, strong) NSDictionary *dataDic;
@end

@implementation ViewController
- (void)viewWillAppear:(BOOL)animated
{
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    [self.view addSubview:webView];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:BASE_URL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"%@",operation.responseObject);
        
        NSData *data = [NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:nil];
        NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@">>>>%@",str);
        NSError *error = nil;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
        NSLog(@">>>>>%@",dic);
        NSString *text = [[dic objectForKey:@"data"] objectForKey:@"text"];
        NSLog(@"%@",text);
//
//        [webView loadHTMLString:text baseURL:nil];
        
//        NSDictionary *totalDic = responseObject;
//        NSLog(@">>>>%@",operation.responseString);
//        //NSString * data = [totalDic valueForKeyPath:@"data"];
//        NSDictionary *array=[totalDic valueForKeyPath:@"data"];
//        NSLog(@"111111%@",array);
//        NSString *content=[array objectForKey:@"content"];
//        NSArray *ck=[content componentsSeparatedByString:@"<p>"];
//        NSString *str=ck[4];
//        NSLog(@"12312312312str%@",str);
//        NSString *str1=[str valueForKeyPath:@"<img src"];
//        NSLog(@"str11111%@",str1);
//        //NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:operation.responseData options:NSJSONReadingAllowFragments error:nil];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
